using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using UnityEngine;

public class ObjectData :   BaseObject
{
    protected string _objKey;
    protected ObjectData _parent;
    private BindManage _bindManage;

    //public BaseObject ProertyNames = new BaseObject();

    public BaseObject ProertyTypes = new BaseObject();

    public ObjectData(ObjectData parent, string objKey)
    {
        _parent = parent;
        _objKey = objKey;
        _bindManage = BindManage.getInstance();
    }

    public ObjectData parent
    {
        get { return _parent; }
        set { _parent = value; }
    }

    public string ObjKey
    {
        get { return _objKey; }
        set { _objKey = value; }
    }

    /**
         *	不通过回调直接取表格
         * @param val 表格名
         * @return 表格对象
         */
    public Record GetRecordEx(string val)
    {
        return GetProperties(val) as Record;
    }

    public System.Object GetPropertiesEx(string PropertiesName)
    {
        if (!CheckProperties(PropertiesName))
        {
            Console.WriteLine("{0}属性不存在", PropertiesName);
			return 0;
        }
        return base.GetProperties(PropertiesName);
    }

    virtual public void HandlePropertiesEx(string PropertiesName, System.Object PropertiesValue)
    {
        base.HandleProperties(PropertiesName, PropertiesValue);
        _bindManage.CallBind(this, PropertiesName, PropertiesValue,true);
    }

    public void UpdataPropertiesEx(string PropertiesName, System.Object PropertiesValue)
    {
        base.HandleProperties(PropertiesName, PropertiesValue);
        //_bindManage.CallView(this as View,PropertiesName,PropertiesValue,true,true);

    }

    virtual public void DeletePropertiesEx(string PropertiesName)
    {
        if (CheckProperties(PropertiesName))
        {
            System.Object PropertiesValue = GetProperties(PropertiesName);
            base.DeleteProperties(PropertiesName);
            _bindManage.CallBind(this, PropertiesName, PropertiesValue, false);

            if (PropertiesValue is ObjectData)
            {
                //假如对象移除，移除该对象所有绑定
                _bindManage.UnbindPropAll((ObjectData)PropertiesValue, PropertiesName);
            }
        }
    }



    /// <summary>
    /// 根据数据流缓存本地数据
    /// </summary>
    /// <param name="count">服务端属性个数</param>
    /// <param name="msg">服务端属性数据</param>
    virtual public void setPropertiesFormByteArrayEx(int count, ByteArrayEx msg)
    {
        for (int i = 0; i < count; i++)
        {
            string name = msg.readMultiByteEx();
            int type = msg.readInt();
            string proName = name;//索引名
            System.Object valData = (System.Object)msg.GetDataByType(type);
            //object valData = (object)msg.GetDataByType((int)ProertyTypes.GetProperties(proName));//属性值(新加就不行了so..)
            HandlePropertiesEx(proName, valData);
        }
    }

}
